* Recode/Clean cross-sectional data from GLES version 2.0.0 (2013)


version 13.1
clear all

use ZA5702_v2-0-0.dta,clear

* Define missings (code provided by GLES team)
include /home/kai/Work/data/gles-2013/ZA5702_missing_v2-0-0.do

* Recodes

* Identify voters in pre-/post-election data
* For pre-election, use: certain, probably, postal vote (bestimmt, wahrscheinlich, Briefwahl=

gen byte wahlbeteiligung = .

* Voters
replace wahlbeteiligung = 1 if v10 <3
replace wahlbeteiligung = 1 if v10 == 6
replace wahlbeteiligung = 1 if n10 == 1

* Non-Voters
replace wahlbeteiligung = 0 if v10 > 2 & v10 <6
replace wahlbeteiligung = 0 if n10 == 2

lab var wahlbeteiligung Wahltbeteiligung

* Gender
recode vn1 (1=1) (2=0), gen(male)
lab var male Mann
lab def male 0 "Frau" 1 "Mann"
lab val male male 

* Age
gen alter = 2014 - vn2c
lab var alter Alter

* Educational attainment (low/mid/high)
recode vn163 (1/2=1 "Bildung: niedrig") (3=2 "Bildung: mittel") (4/5=3 "Bildung: hoch") (else= .),gen(bildung)

* Rename East/West var (all of Berlin is East)
recode ostwest (1=1 ja) (2=0 nein),gen(ost)

* Alternative: derive from electoral district code
recode elecdist (1/55=0) (56/76=1) (77/82=0) (83/86=1) (87/150=0) (151/166=1) (167/188=0) (189/197=1) (198/299=0) ,gen(distostwest)

lab var distostwest "Region"
lab def distostwest 0 "West" 1 "Ost"
lab val distostwest distostwest

* Has party identification
recode vn119a (1/801 = 1 "PI vorhanden") (808= 0 "PI: nein") (809=.),gen(pi)

* Which party identification

recode vn119a (1/3=1 union) (4= 2 spd) (5=3 fdp) (6=4 gruene) (7=5 linke) (322=6 afd) (808 = 0 keine) (.a .b 809=.) (else = 7 andere), gen(pityp)

* Single category for ID: other/none/AfD
recode pityp (0 6 7 = 0) , gen(pitypsimple)
lab def pitypsimple 0 "keine/andere" 1 union 2 spd 3 fdp 4 gruene 5 linke 
label values pitypsimple pitypsimple

* Generate party identification stubs for clogit

gen byte altpi1 = pitypsimple == 1
gen byte altpi2 = pitypsimple == 2
gen byte altpi3 = pitypsimple == 3
gen byte altpi4 = pitypsimple == 4
gen byte altpi5 = pitypsimple == 5

forvalues v = 1/5 {
	replace altpi`v' = . if pitypsimple == .
	}

* Generate stubs for candidates

gen altcandidate1 = vn22a
lab var altcandidate1 "Bewertung Merkel"
gen altcandidate2 = vn22b
lab var altcandidate2 "Bewertung Steinbr�ck"
gen altcandidate3 = vn22c
lab var altcandidate3 "Bewertung Br�derle"
gen altcandidate4 = vn22e
lab var altcandidate4 "Bewertung Trittin"
gen altcandidate5 = vn22d
lab var altcandidate5 "Bewertung Gysi"


* Generate stubs for ideological distance
gen altiddist1 = abs(vn62 - vn60a)
replace altiddist1 = abs(vn62 - vn60b) if bl == 2
* SPD 
gen altiddist2 = abs(vn62 - vn60c)
gen altiddist3 = abs(vn62 - vn60d)
gen altiddist4 = abs(vn62 - vn60f)
gen altiddist5 = abs(vn62 - vn60e)

* Church attendance

recode vn193 (1/2= 0 "Kirchgang: selten-nie") (3=1 "Kirchgang: gelegentlich") (4/8=2 "Kirchgang: haeufig"),gen(religpractice)

* Union membership
recode vn213a (1/3 =1 Gewerkschaftsmitglied) (4=0 nein),gen(gewerkschaft)

* Happy with way democracy works
gen demzufriedenheit = 6 - vn6
lab var demzufriedenheit "Zufriedenheit: Demokratie"

* single-person household

recode vn158 (1=1) (else=0),gen(einpersonenhaushalt)
lab var einpersonenhaushalt "Einpersonenhaushalt"

* interest in politics

gen interesse = 6 - vn3
lab var interesse Politikinteresse

* perception: turnout in neighbourhood

gen wbnachbarn = 6- v149

gen nachwahl = datum >92213

* itention to vote

* Pre-election
recode v11bb (1=1 UNION) (4=2 SPD) (5=3 FDP) (6=4 GRUENE) (7=5 LINKE) (322=6 AFD) (else=.), gen(wahlmitafd)
lab var wahlmitafd "Wahlentscheidung 2013 mit AfD"

* Postal pre-election
replace wahlmitafd = 1 if v12bb == 1
replace wahlmitafd = 2 if v12bb == 4
replace wahlmitafd = 3 if v12bb == 5
replace wahlmitafd = 4 if v12bb == 6
replace wahlmitafd = 5 if v12bb == 7

* Postelection

replace wahlmitafd = 1 if n11bb == 1
replace wahlmitafd = 2 if n11bb == 4
replace wahlmitafd = 3 if n11bb == 5
replace wahlmitafd = 4 if n11bb == 6
replace wahlmitafd = 5 if n11bb == 7
replace wahlmitafd = 6 if n11bb == 322 

* Simplify: 5 parys plus other
recode v11bb (1=1 UNION) (4=2 SPD) (5=3 FDP) (6=4 GRUENE) (7=5 LINKE) (171/322=6 Sonstige) (else=.), gen(wahlmitsonstigen)
lab var wahlmitsonstigen "Wahlentscheidung 2013 mit Sonstigen"

* Postal: pre-election
replace wahlmitsonstigen = 1 if v12bb == 1
replace wahlmitsonstigen = 2 if v12bb == 4
replace wahlmitsonstigen = 3 if v12bb == 5
replace wahlmitsonstigen = 4 if v12bb == 6
replace wahlmitsonstigen = 5 if v12bb == 7
replace wahlmitsonstigen = 6 if v12bb > 7 & v12bb < 323

* post-election

replace wahlmitsonstigen = 1 if n11bb == 1
replace wahlmitsonstigen = 2 if n11bb == 4
replace wahlmitsonstigen = 3 if n11bb == 5
replace wahlmitsonstigen = 4 if n11bb == 6
replace wahlmitsonstigen = 5 if n11bb == 7
replace wahlmitsonstigen = 6 if n11bb > 7 & n11bb < 323

* Even more simple: other -> missing

recode wahlmitsonstigen (6=.),gen(wahlfuenf)
lab var wahlfuenf "Wahlentscheidung (fuenf Parteien)"
lab def parties 1 "Union" 2 "SPD" 3 "FDP" 4 "B90Gruene" 5 "Linke"
lab val wahlfuenf parties


* Thermometer. Problem: AfD has many missings
* Union: CSU in Bavaria, CDU everywhere else

gen skalounion = vn21a
replace skalounion = vn21b if bl == 2
gen skalospd = vn21c
gen skalofdp = vn21d
gen skalolinke = vn21e
gen skalogruene = vn21f
gen skaloafd = vn21h


foreach partei in union spd fdp linke gruene afd {
	lab var skalo`partei' "`partei'"
	}

* better variable names
gen unterschiedereduzieren = 6 - vn40d
lab var unterschiedereduzieren "Regierung: Einkommensunterschiede reduzieren"

* Left-Right-Selfplacement
clonevar lire = vn62
lab var lire "LRS"

* General evaluation of the economy
gen wilagut = 6- vn29
lab var wilagut "Allgemeine WiLa gut"

* Socialism

clonevar prosozialismus = vn73e

lab var prosozialismus "Sozialismus gute Idee"

* Afraid of: sovereign debt crisis

gen angstschulden = 6 - vn35
lab var angstschulden "Schuldenkrise: Angst"

* welfare state/taxation

clonevar sozialsteuern = vn67
lab var sozialsteuern "Steuern/Sozialleistungen"

* against immigration

clonevar gegenzuwanderung = vn68
lab var gegenzuwanderung "Ablehnung: Zuwanderung"

* social justice important

gen gerechtigkeitwichtig = 6- vn153
lab var gerechtigkeitwichtig "Mehr Gerechtigkeit"


* Satisfied with government performance

clonevar regzufriedenheit = v74
replace regzufriedenheit = n74 if nachwahl
label var regzufriedenheit "Zufriedenheit Regierung"

* save data

save querschnitt-2013.dta , replace 

